import os
import time

def adb_ready():
    os.system("adb connect 127.0.0.1:62001")
    apk_path = "./com.xingjiabi.shengsheng_8.0.0.2.apk"
    os.system(f"adb install {apk_path}")
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
cap = {}
cap['appPackage'] = "com.threegene.doctor"
cap['appActivity'] = ".module.splash.SplashActivity"
cap['deviceName'] = "d2q"
cap['platformVersion'] = "7.1.2"
cap['platformName'] = "Android"

driver = webdriver.Remote("http://localhost:4723/wd/hub",cap)
driver.implicitly_wait(15)
# 点击同意
driver.find_element(MobileBy.ID,"com.threegene.doctor:id/agree_user_agreement_btn").click()
# 等待跳转
time.sleep(3)
# 滑动
TouchAction(driver).press(x = 684,y = 1044).move_to(x = 36,y = 863).release().perform()  # 从x684到y1044滑动到x的36，y的863，松开双指，并执行
time.sleep(3)
TouchAction(driver).press(x = 684,y = 1044).move_to(x = 36,y = 863).release().perform()
# 点击立即体验
driver.find_element(MobileBy.ID,"com.threegene.doctor:id/submit_btn").click()
# 点击阅读
driver.find_element(MobileBy.CLASS_NAME,"android.widget.CompoundButton").click()
# 点击手机号登录
driver.find_element(MobileBy.ID,"com.threegene.doctor:id/tv_phone_login").click()
# 输入内容
driver.find_element(MobileBy.ID,"com.threegene.doctor:id/edit_phone_number").send_keys("15948551301")
# 点击发送验证码
driver.find_element(MobileBy.ID,"com.threegene.doctor:id/tv_send_code").click()
# 断言文本
text = WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((MobileBy.ID,"com.threegene.doctor:id/sms_send_hint"))).text
assert text in "已发送验证码至159****1301"









